package com.base.sdk.util;

import android.support.annotation.NonNull;
import android.text.TextUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * Created by Administrator on 2018/4/12/012.
 */

public class DateFormatUtil {
    /**
     * 时间格式化
     *
     * @return
     */
    public static String dateFormat(Long date) {
        if (date != null) {
            return new SimpleDateFormat("yyyy年MM月").format(new Date(date));
        } else {
            return "";
        }
    }

    /**
     * 时间格式化
     *
     * @return
     */
    public static String dateFormatAll(Long date) {
        if (date != null) {
            return new SimpleDateFormat("yyyy/MM/dd").format(new Date(date));
        } else {
            return "";
        }
    }

    /**
     * 时间格式化
     *
     * @return
     */
    public static String dateFormatLine(Long date) {
        if (date != null) {
            return new SimpleDateFormat("yyyy-MM-dd").format(new Date(date));
        } else {
            return "";
        }
    }

    /**
     * 时间格式化
     *
     * @return
     */
    public static String timeFormat(Long date) {
        if (date != null) {
            return new SimpleDateFormat("MM月dd日 HH:mm").format(new Date(date));
        } else {
            return "";
        }
    }

    public static String deleteKongGe(String data) {
        if (TextUtils.isEmpty(data)) {
            return "";
        } else {
            if (data.contains(" ")) {
                return data.substring(0, data.indexOf(" "));
            } else {
                return data;
            }
        }
    }

    public SimpleDateFormat lineFormat = new SimpleDateFormat("yyyy-MM-dd");

    public Calendar getCalendar(String dateStr) throws ParseException {
        Date date = lineFormat.parse(dateStr);
        Calendar c = Calendar.getInstance();
        c.setTime(date);
        return c;
    }

    public String getMonth(String dataStr) throws ParseException {
        Calendar calendar = getCalendar(dataStr);
        return (calendar.get(Calendar.MONTH) + 1) + "";
    }

    public String getWeek(int week) {
        String str = "";
        if (week == 1) {
            str = "周一";
        } else if (week == 2) {
            str = "周二";
        } else if (week == 3) {
            str = "周三";
        } else if (week == 4) {
            str = "周四";
        } else if (week == 5) {
            str = "周五";
        } else if (week == 6) {
            str = "周六";
        } else if (week == 0) {
            str = "周日";
        }
        return str;
    }
}
